package com.gqmk.demo.springcloudconsumer.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RoundRobinRule;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
// 开启微服务注册和发现
@EnableDiscoveryClient
public class RestConfig {

    @Bean
    @LoadBalanced // Ribbon （消费者端）负载均衡
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    // 调整 负载均衡 策略
//    @Bean
    public IRule myLoadBalancedRule() {
        return new RoundRobinRule(); // 默认轮询策略 RoundRobinRule
    }

}
